<template>
  <div class="page">
    <Navbar title="项目详情" />
    <van-tabs v-model="activeTab" color="#4B93FE">
      <van-tab title="项目信息" :name="0" />
      <van-tab title="项目进度" :name="1" />
    </van-tabs>
    <div v-show="activeTab === 0" class="content">
      <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
        <div class="list-item">
          <div class="header f-r j-b a-c">
            <div class="title">{{ detail.projectName }}</div>
          </div>
          <div class="label">
            项目类型：{{ type4[detail.auditType] }}
          </div>
          <div class="label">
            项目编码：{{ detail.projectCode }}
          </div>
          <div class="label">
            建设类型：{{ type[detail.projectType] }}
          </div>
          <div class="label">
            建设地点详情：{{ detail.placeCodeDetail }}
          </div>
          <div class="label">
            国标行业名称：{{ detail.industryName }}
          </div>
          <div class="label">
            项目属性：{{ type[detail.projetAttribute] }}
          </div>
          <!-- <div class="label">
            审核类型：{{ type4[detail.auditType] }}
          </div> -->
          <div class="label">
            我的代办员：{{ detail.handleLeader }} {{ detail.handlePhone }}
          </div>
          <div class="label">
            总投资：{{ detail.totalAmount }}（万元）
          </div>
          <div class="label">
            项目单位名称：{{ detail.enterpriseName }}
          </div>
          <div class="label">
            进度状态：{{ detail.progressName }}
          </div>
          <div class="label" style="margin-bottom: 0">
            领码日期：{{ detail.codingTime }}
          </div>
        </div>
        <el-button type="primary" style="width: 100%;margin: 20px 0;" @click="routerJump">项目投资码</el-button>
        <div class="record-list">
          <div class="title">项目服务记录</div>
          <van-empty v-if="!tableData.length" description="暂无数据" />
          <div
            v-for="(item,index) in tableData"
            :key="index"
            class="record-item"
          >
            <help1 v-if="item.types == 0" :item="item" />
            <help2 v-if="item.types == 1" :item="item" />
            <help3 v-if="item.types == 2" :item="item" />
            <help4 v-if="item.types == 3" :item="item" />
          </div>
        </div>
      </van-pull-refresh>
    </div>
    <ProjectCanvas v-if="activeTab === 1" />
  </div>
</template>

<script>
import refresh from '@/mixins/refresh'
import { http_project } from '@/api'
import { helpGType, progressStatus, qsStatus, qsType } from '@/eumn'
import Help1 from '@/views/my/help/help1'
import Help2 from '@/views/my/help/help2'
import Help3 from '@/views/my/help/help3'
import Help4 from '@/views/my/help/help4'
import ProjectCanvas from '@/views/my/project-canvas'
import { Toast } from 'vant'

export default {
  name: 'ProjectDetail',
  components: { ProjectCanvas, Help1, Help2, Help3, Help4 },
  mixins: [refresh],
  data() {
    return {
      activeTab: 0,
      detail: {
        
      },
      projectId: '',
      type: {
        'A00003': '其他项目',
        'A00001': '民间固定资产投资项目',
        'A00002': '国有控股项目'
      },
      type2: ['新建', '扩建', '迁建', '改建', '其他'],
      type3: {
        'A00003': '其他项目',
        'A00001': '民间固定资产投资项目',
        'A00002': '国有控股项目'
      },
      type4: {'01':'审批', '02':'核准', '03':'备案'}
    }
  },
  created() {
    const type = localStorage.getItem('type')
    if (type !== undefined && type !== 1) {
      this.activeTab = 1
      localStorage.setItem('type',1)
    }
  },
  methods: {
    onRefresh() {
      const { projectId } = this.$route.query
      this.projectId = projectId
      http_project.detail({
        id: projectId
      }).then(res => {
        this.detail = {
          ...res.data,
          progressName: progressStatus.getName(res.data.progress)
        }
      })

      this.pageNo = 1
      this.getList()
    },
    getList() {
      const { projectId } = this.$route.query
      if (this.pageNo > 1 && this.tableData.length >= this.totalSize) return Toast('没有更多了')
      http_project.helpPage({
        ...this.getQueryParams(),
        projectId: projectId
      }).then(res => {
        if (this.pageNo === 1) {
          this.tableData = res.data.map(el => {
            return {
              ...el,
              types: Number(el.types),
              typeName: qsType.getName(el.types),
              gTypeName: helpGType.getName(el.gtype),
              statusName: qsStatus.getName(el.status),
              statusColor: qsStatus.getColor(el.status)
            }
          })
        } else {
          this.tableData = [
            ...this.tableData,
            ...res.data.map(el => {
              return {
                ...el,
                types: Number(el.types),
                typeName: qsType.getName(el.types),
                gTypeName: helpGType.getName(el.gtype),
                statusName: qsStatus.getName(el.status),
                statusColor: qsStatus.getColor(el.status)
              }
            })
          ]
        }
        this.totalSize = res.data.total
        this.refreshLoading = false
      })
    },
    routerJump() {
      this.$router.push({
        path: '/project-code2',
        query: {
          projectId: this.projectId,
          projectName: this.detail.projectName,
          vconsole: true
        }
      })
    }

  }
}
</script>

<style scoped lang="scss">
.page {
    .list-item {
        width: 100%;
        background: #FFFFFF;
        border-radius: 10px;
        padding: 20px;
        .header {
            .title {
                font-size: 18px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-right: 10px;
            }
            margin-bottom: 23px;
        }
        .label {
            font-size: 15px;
            line-height: 15px;
            // height: 15px;
            color: #333333;
            margin-bottom: 15px;
            &:last-of-type {
                margin-bottom: 0;
            }
        }
    }
    .record-list {
        background: #FFFFFF;
        border-radius: 10px;
        padding: 20px;
        .title {
            font-size: 16px;
            font-family: PingFang SC;
            font-weight: bold;
            color: #333333;
            margin-bottom: 20px;
        }
        .record-item {
            margin-bottom: 20px;
            border: 1px solid #2B80FF;
            padding: 7px 12px 13px;
            border-radius: 10px;
            overflow: hidden;
            background-color: #fff;
            position: relative;
            .link {
                height: 12px;
                font-size: 12px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #2F86FD;
            }
            .label {
                height: 12px;
                font-size: 12px;
                color: #333333;
                margin-bottom: 15px;
                &:last-of-type {
                    margin-bottom: 0;
                }
            }

            .button1 {
                color: #2B80FF;
                width: 59px;
                height: 24px;
                background: #D8E8FF;
                border: 1px solid #2F86FD;
                border-radius: 10px;
                text-align: center;
                font-size: 12px;
                line-height: 22px;
                margin-bottom: 15px;
            }
            .status {
                width: 50px;
                height: 21px;
                line-height: 21px;
                font-size: 12px;
                color: #fff;
                border-radius: 0px 10px 0px 0px;
                position: absolute;
                right: -1px;
                top: 0;
                text-align:center;
            }
            .status1 {
                background: #4B93FE;
            }
            .status2 {
                background: #20B153;
            }
        }
    }
    .el-button {
        background-color: #2F86FD;
        border-color: #2F86FD;
        border-radius: 10px;
    }
}
</style>
